<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'basic';
$return=array();
$tabs=array(
	array('op'=>'basic','title'=>'基本参数设置'),
	array('op'=>'message_tpl','title'=>'模版消息设置'),
	array('op'=>'sms_tpl','title'=>'短信模版设置'),
	array('op'=>'diy','title'=>'自定义名称'),
	array('op'=>'vip','title'=>'激活套餐设置'),
	array('op'=>'vip_fileds','title'=>'激活自定义表单设置'),
	array('op'=>'sendtest','title'=>'模板消息测试'),
);
if($_RQ['op']=='basic'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$this->plugin_setting('basic',$postdata);
		exi('设置成功');
	}
	$return['item']=$this->plugin_setting('basic');
	$footernav = array(
			array('title'=>'首页','icon'=>'icon-shouye','color'=>'#cc99ff','action'=>'jy_yuyue/index/'),
			array('title'=>'项目','icon'=>'icon-quanbudingdan','color'=>'#66cc99','action'=>'jy_yuyue/sever/'),
			array('title'=>'技师','icon'=>'icon-service','color'=>'#ff9933','action'=>'jy_yuyue/worker/'),
			array('title'=>'我的','icon'=>'icon-wo1','color'=>'#66cc66','action'=>'jy_yuyue/home/'),
	);
	$return['item']['footernav'] = !empty($return['item']['footernav']) ? $return['item']['footernav'] : $footernav;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'tabs'=>$tabs,
		'edit'=>array(
		    array('type'=>'string','title'=>'门店名称','name'=>'name','help'=>''),
			array('type'=>'string','title'=>'公告','name'=>'notice'),
			array('type'=>'unitstring','title'=>'可预定天数范围','name'=>'days','unit'=>'天'),
			array('type'=>'switch','title'=>'支持退款？','name'=>'refundopen'),
			array('type'=>'time_hour','title'=>'营业时间','name'=>'work_time'),
			array('type'=>'string','title'=>'门店电话','name'=>'phone'),
			array('type'=>'string','title'=>'门店地址','name'=>'address'),
			array('type'=>'text','title'=>'门店详情','name'=>'remark'),
			array('name'=>'isworker','title'=>'是否关闭服务员后台','type'=>'switch','help'=>'关闭后，服务员无法访问手机管理端'),
			//array('name'=>'hold','title'=>'是否开启订单保留','type'=>'switch','help'=>''),
			array('name'=>'timeout','title'=>'保留时长','type'=>'unitstring','help'=>'','unit'=>'分钟','help'=>'不填写则默认五分钟'),
			array('type'=>'string','title'=>'自定义服务时间单位','name'=>'timesunit','help'=>'默认“分钟”！'),
			array('type'=>'switch','title'=>'支持《微客分销》分销商发起预约项目','name'=>'is_fenxiaoset','help'=>'开启后，微客分销手机端，可以发现预约项目，然后提供给客户预约专家使用！'),
			array('type'=>'switch','title'=>'不显示人均消费','name'=>'norenjun'),
			array('type'=>'switch','title'=>'评论审核','name'=>'shenhe'),
			array('name'=>'ruzhu','title'=>'是否开启服务人员入驻','type'=>'switch','help'=>'开启入驻则他人可自行注册申请成为服务人员'),
			array('name'=>'dingwei','title'=>'是否关闭自动定位','type'=>'switch','help'=>''),
			array('name'=>'iscredit','title'=>'是否关闭余额支付','type'=>'switch','help'=>''),
			array('type'=>'switch','title'=>'技师可以添加项目？','name'=>'worker_serve'),
			array('type'=>'string','title'=>'可预约人数','name'=>'yuyue_num','help'=>'默认只能同时预约1人'),
			array(
					'type'=>'array',
					'name'=>'image',
					'add_tip'=>'添加一个幻灯片',
						'list'=>array(
							array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片'),
							array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
							
						),
						'details'=>array(
							array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片','help'=>''),
							array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
							
						)
			),
			array('type'=>'array','name'=>'footernav','add_tip'=>'添加一个底部导航',
									'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标'),
										array('type'=>'string','name'=>'action','title'=>'导航链接'),
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标'),
										array('type'=>'link','name'=>'action','from'=>'action','title'=>'导航链接'),
									)
			),
			array('type'=>'string','title'=>'分享标题','name'=>'share_title'),
			array('type'=>'image','title'=>'分享图片','name'=>'share_image'),
			array('type'=>'string','title'=>'分享描述','name'=>'share_desc'),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='message_tpl'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array_fields(array('isnew','confirm','cancel','tuikuan','disagree','admin_ids'),$postdata);
		$this->plugin_setting('message_tpl',$data);
		exi('设置成功');
	}
	$return['item']=$this->plugin_setting('message_tpl');
	$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'tabs'=>$tabs,
		'edit'=>array(
			array('type'=>'tip','title'=>'[温馨提示]：公众号类别勿必选择：生活服务--百货/超市/便利店；这样可以自动创建，触发消息！'),
			array('type'=>'choose_many','name'=>'admin_ids','title'=>'通知管理员','choose_title'=>'选择通知人','help'=>'如不填写，则不发送结算通知给管理员','action'=>'core/member.get_member/many'),
			array('type'=>'switch','title'=>'开启预约通知员工消息模版','name'=>'isnew','help'=>''),
			array('type'=>'switch','title'=>'开启预约已确认通知消息模版','name'=>'confirm','help'=>''),
			array('type'=>'switch','title'=>'开启预约被取消通知消息模版','name'=>'cancel'),
		//	array('type'=>'switch','title'=>'退款成功通知消息模版','name'=>'tuikuan'),
		//	array('type'=>'switch','title'=>'退款被拒绝通知消息模版','name'=>'disagree'),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='sms_tpl'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array_fields(array('notice'),$postdata);
		$this->plugin_setting('sms_tpl',$data);
		exi('设置成功');
	}
	$return['item']=$this->plugin_setting('sms_tpl');
	$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'tabs'=>$tabs,
		'edit'=>array(
			array('type'=>'string','title'=>'新订单通知模版','name'=>'notice'),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='diy'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array_fields(array('store','serve','worker','home'),$postdata);
		$this->plugin_setting('diy',$data);
		exi('设置成功');
	}
	$return['item']=$this->plugin_setting('diy');
	$htmls=array(
		'type'=>'edit',
		'desc'=>'自定义名称',
		'tabs'=>$tabs,
		'edit'=>array(
			array('type'=>'string','title'=>'自定义《技师》名称','name'=>'worker','help'=>'修改后将替换《技师》名称'),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='vip'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array_fields(array('month','quarter','year','vip_img','vip_bg','openvip'),$postdata);
		$this->plugin_setting('vip',$data);
		exi('设置成功');
	}
	$return['item']=$this->plugin_setting('vip');
	$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'tabs'=>$tabs,
		'edit'=>array(
			array('type'=>'switch','title'=>'是否开启预约激活功能','name'=>'openvip','help'=>''),
			array('type'=>'string','title'=>'月费','name'=>'month','help'=>'激活一月的费用'),
			array('type'=>'string','title'=>'季费','name'=>'quarter','help'=>'激活一季度的费用'),
			array('type'=>'string','title'=>'年费','name'=>'year','help'=>'激活一年的费用'),
			array('type'=>'image','title'=>'首页激活图片','name'=>'vip_img','help'=>''),
			array('type'=>'image','title'=>'激活页背景','name'=>'vip_bg','help'=>''),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='vip_fileds'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array_fields(array('vip_fileds'),$postdata);
	//	$hasdata=pdo_count('jy_yuyue_vip_data',array('uniacid'=>$_SESSION['uniacid']));
		$vip_fileds=$this->plugin_setting('vip_fileds');
		$this->plugin_setting('vip_fileds',$data);
		/* if($hasdata==0){
			if(!$vip_fileds){
			$this->plugin_setting('vip_fileds',$data);
			if($postdata['vip_fileds']){
				foreach ($vip_fileds as $item) {
					$insert                = array();
					$insert['uniacid']     = $_SESSION['uniacid'];
					$insert['title']       =trim($item['title']);
					$insert['type']        =trim($item['type']);
					$insert['ismust']        =intval($item['ismust']);
					$insert['paixu']        =intval($item['paixu']);
					$insert['value']        =trim($item['value']);
					pdo_insert('jy_yuyue_vip_fileds', $insert);
				}
				
			}
			}else{
			pdo_delete('jy_yuyue_vip_fileds',array('uniacid'=>$_SESSION['uniacid']));
			foreach ($vip_fileds as $item) {
				$insert                = array();
				$insert['uniacid']     = $_SESSION['uniacid'];
				$insert['title']       =trim($item['title']);
				$insert['type']        =trim($item['type']);
				$insert['ismust']        =intval($item['ismust']);
				$insert['paixu']        =intval($item['paixu']);
				$insert['value']        =trim($item['value']);
				pdo_insert('jy_yuyue_vip_fileds', $insert);
			}
			}
		}
		*/
		exi('设置成功');
	}
	$return['item']=$this->plugin_setting('vip_fileds');
	$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'tabs'=>$tabs,
		'edits'=>array(
					array(
							'title'=>'自定义字段',
							'list'=>array(
								array('type'=>'array','name'=>'vip_fileds','add_tip'=>'添加一个字段（温馨提示：已经有用户提交过数据的表单，不允许再编辑和添加新字段！）',
								'list'=>array(
									array('type'=>'string','name'=>'title','title'=>'字段名称'),	
									array('type'=>'radio','name'=>'type','title'=>'字段类型','options'=>'types'),	
									array('type'=>'radio','name'=>'ismust','title'=>'必填','options'=>'ismust'),	
									array('type'=>'string','name'=>'paixu','title'=>'排序'),	
									array('type'=>'string','name'=>'value','title'=>'选项信息'),	
								),
								'details'=>array(
									array('type'=>'string','name'=>'title','title'=>'字段名称'),	
									array('type'=>'select','name'=>'type','title'=>'字段类型','options'=>'type','option_title'=>'type'),
									array('type'=>'switch','name'=>'ismust','title'=>'必填','help'=>''),
									array('type'=>'string','name'=>'paixu','title'=>'排序','help'=>'从小到大顺序排序'),
									array('type'=>'string','name'=>'value','title'=>'选项信息','help'=>'单选和多选设置此条信息，选项之间以英文分号;隔开，例如:选项1;选项2;选项3'),
								)
								),
							)
						),
		),
	);
	$return['type']=array(array('id'=>1,'type'=>'字符串'),array('id'=>2,'type'=>'数字'),array('id'=>3,'type'=>'图片'),array('id'=>4,'type'=>'单选'),array('id'=>5,'type'=>'多选'),array('id'=>6,'type'=>'文本'),array('id'=>7,'type'=>'地址'));
	$return['types']=array('1'=>'字符串','2'=>'数字','3'=>'图片','4'=>'单选框','5'=>'多选框','6'=>'文本','7'=>'地址');
	$return['ismust']=array('0'=>'否','1'=>'是');
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='yuyue_xieyi'){
	$item=$this->plugin_setting('yuyue_xieyi');
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post1',
		'desc'=>'预约注意事项',
		'edit'=>array(
					array('type'=>'richtext','title'=>'预约注意事项','name'=>'content'),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post1'){
	$postdata=get_postdata();
	$item=$this->plugin_setting('yuyue_xieyi',$postdata);
	exi('设置成功');
}
if($_RQ['op']=='sendtest'){
	if($_RQ['postdata']){
		$post=get_postdata();
		if(!$post['mid']){
			exi('请先选择发送给会员的MID！','error');
		}
		if(!$post['orderid']){
			exi('请先输入订单ID！','error');
		}
		$order=pdo_get('jy_yuyue_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['orderid']));
		if($post['type']){
			$this->model('notice')->notice_orderget($order['id'],'',1);
		}else{
			$this->model('notice')->notice_workermsg($order,1);
		}
		exi('发送成功！','');
	}
	$return['item']=array();
	$return['htmls']=array(
			'type'=>'edit',
			'desc'=>'测试发送',
			'edit'=>array(
				array('type'=>'string','title'=>'发送给会员的MID','name'=>'mid','help'=>'该会员必须关注公众号'),
				array('type'=>'string','title'=>'输入订单ID','name'=>'orderid','help'=>'现有订单ID'),
				array('type'=>'radio','title'=>'选择类型','name'=>'type','options'=>'types'),
			),
	);
	$return['types']=array('预约通知员工消息模版','技师订单派送通知');
	exi($return);
}